package app.demo.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.springleaf.core.json.IJsonObject;
import org.springleaf.utils.Obj2MapUtils;

/**
 * 用户菜单
 * 
 * @author leaf
 */
@Entity
public class Menu implements IJsonObject {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	//父菜单
	@ManyToOne
	private Menu parent;

	//子菜单
	@OneToMany(mappedBy="parent")
	private List<Menu> children = new ArrayList<Menu>();
	
	private String text;

	private String icon;

	private String action;
	
	private boolean isLeaf;

	public Object toJSonObject() {
		return Obj2MapUtils.toMapExcep(this, new String[]{"parent"});
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Menu getParent() {
		return parent;
	}

	public void setParent(Menu parent) {
		this.parent = parent;
	}

	public List<Menu> getChildren() {
		return children;
	}

	public void setChildren(List<Menu> children) {
		this.children = children;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public boolean isLeaf() {
		return isLeaf;
	}

	public void setLeaf(boolean isLeaf) {
		this.isLeaf = isLeaf;
	}

}
